package cn.datawin.task;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.bson.types.ObjectId;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.sun.org.apache.bcel.internal.generic.NEW;

import cn.datawin.task.dao.DbUtil;
import cn.datawin.task.dao.Resource;
import cn.datawin.task.util.PropertiesUtil;

public class Ganji {
	static String client = "113.106.132.210:6081,113.106.132.210:6082,113.106.132.210:6083,113.106.132.210:6084,113.106.132.210:7075,59.51.73.6:11078,59.51.73.6:19040,113.106.132.210:7074,113.106.132.210:7076,59.51.73.6:19042,113.106.132.210:7077,59.51.73.6:19041,59.51.73.6:19039,59.51.73.6:15039,59.51.73.6:15041,59.51.73.6:15040,59.51.73.6:11079,59.51.73.6:15038,59.51.73.6:11080,114.104.163.157:1125,113.106.132.210:8181,115.239.189.246:16005,113.106.132.210:8187,113.106.132.210:8180,113.106.132.210:8179,113.106.132.210:9051,113.106.132.210:9050,113.106.132.210:9052,113.106.132.210:9049,59.51.73.6:11081";
	static String url = "http://wap.ganji.com/gongsi/";
	public static void main(String[] args) throws IOException, InterruptedException {
		Resource resource = new Resource("/client.properties");
		Properties props = PropertiesUtil.loadProperties(resource);
		Config.apps.putAll(PropertiesUtil.toMap(props));
		DbUtil.connect();
		DBCollection dbc = DbUtil.getcoll("task");
		DBObject dbo =  dbc.findOne(new BasicDBObject("_id", new ObjectId("54dace0de4b091ca36352997")));
		dbo.put("client", client.split(","));
		int a = Integer.parseInt(Config.apps.get("tasknum")); // 初始值
		dbo.removeField("_id");
		dbo.put("state", "0");
		dbo.put("root", false);
		// 50 0000
		for(int j=1; j<=10000; j++){
			List<DBObject> list = new ArrayList<DBObject>();
			for(int i=1;i<=100;i++){
				dbo.put("url", url+a);
				list.add(new BasicDBObject(dbo.toMap()));
				a++;
			}
			System.out.println(a);
			dbc.insert(list);
		}
	}

}
